home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-05-22 | 1.5 KB | 78 lines | [TEXT/CWIE] |
- // =================================================================================
- // GenText.cp ©1997 BB's Team inc. All rights reserved
- // =================================================================================
- #include "PL_Utils.h"
- #include "GenText.h"
-
-
- // ctor
- GenText::GenText ()
- : mText (nil)
- , mAutoContrast (true)
- {}
-
-
- // dtor
- GenText::~GenText ()
- {
- MakeRoom();
- }
-
-
- // Make room.
- void GenText::MakeRoom (void)
- {
- if ( mText != nil ) {
- DisposeHandle (mText);
- mText=nil;
- }
- }
-
-
- // The contrast checkbox has changed
- void GenText::SetContrast (Boolean inContrast)
- {
- MakeRoom ();
- mAutoContrast = inContrast;
- }
-
-
- // Generates the text
- void GenText::Update (FontLight& font, ImageLight& image)
- {
- // ought to be already done at that point
- MakeRoom ();
-
- // Allocate the Handle for the resulting text
- PL_Utils::ForceNewHandle (mText, image.GetTextSize());
- if (mText == nil)
- return;
-
- // Prepare synchronization between the image and the font's lighness
- float fMin, fMax, lightMin, lightMax;
- font.GetMinMax (fMin, fMax);
-
- if (mAutoContrast)
- image.GetMinMax (lightMin, lightMax);
- else {
- lightMin = 0.;
- lightMax = 1.;
- }
-
- // Compute each image character equivalent
- Int32 k = 0;
- float u;
- float scale = (fMax-fMin)/(lightMax-lightMin);
-
- for (Int16 i=0 ; i<image.GetHeightN() ; i++) {
- for (Int16 j=0 ; j<image.GetWidthN() ; j++) {
- u = fMin + scale * (image[k]-lightMin);
- (*mText)[k] = font.ComputeChar (u);
- k++;
- }
- (*mText)[k++]='\r';
- }
-
- return;
- }
-